#include "Bloc.h"

using namespace SDL::UTILS;
using namespace SDL::ELEMENTS;

Uint16 const Bloc::BASIC_LIFE = 100;


Bloc::Bloc(std::string const& _type, Sprite _currentSprite, Uint16 _life)
	: AElement(), m_type(_type), m_life(_life), m_currentSprite(_currentSprite)
{
	m_surface = &m_currentSprite.Src;
}

Bloc::~Bloc()
{
	m_surface = NULL;
}

bool Bloc::Draw(SDL_Surface* _screen)
{
	if (m_hidden == false)
	{
		m_currentSprite.Src.BlitSurface(&m_currentSprite.CurrentFrame, _screen, &m_position);
		m_currentSprite.Animate();
	}
	return (true);
}

void Bloc::DecreaseLife(Uint16 _value)
{
	m_life -= _value;
	if ((Sint16)m_life < 0)
		m_life = 0;
}

void Bloc::IncreaseLife(Uint16 _value)
{
	m_life += _value;
}

void Bloc::SetPosition(Sint16 _x, Sint16 _y)
{
	m_position.SetX(_x);
	m_position.SetY(_y);
}

void Bloc::SetPosition(Rect const& _position)
{
	m_position.SetX(_position.GetX());
	m_position.SetY(_position.GetY());
}

void Bloc::Move(Sint16 _offsetX, Sint16 _offsetY)
{
	m_position.SetX(m_position.GetX() + _offsetX);
	m_position.SetY(m_position.GetY() + _offsetY);
}

void Bloc::Move(Rect const& _offset)
{
	m_position.SetX(m_position.GetX() + _offset.GetX());
	m_position.SetY(m_position.GetY() + _offset.GetY());
}

void Bloc::Duplicate(Bloc& _dst) const
{
	_dst.m_currentSprite = m_currentSprite;
	_dst.m_disabled = m_disabled;
	_dst.m_hidden = m_hidden;
	_dst.m_life = m_life;
	_dst.m_position = m_position;
	_dst.m_surface->SetSurface(m_surface->GetSurface());
	_dst.m_type = m_type;
}

Uint16 Bloc::GetLife() const
{
	return (m_life);
}

void Bloc::SetLife(Uint16 _life)
{
	m_life = _life;
}

std::string const& Bloc::GetType() const
{
	return (m_type);
}

Sprite* Bloc::GetCurrentSprite()
{
	return (&m_currentSprite);
}

void Bloc::SetCurrentSprite(Sprite _currentSprite)
{
	m_currentSprite = _currentSprite;
	m_surface = &m_currentSprite.Src;
}
